import vue from '@vitejs/plugin-vue';

import createAutoImport from './auto-import';
import createCompression from './compression';
import createSetupExtend from './setup-extend';
import createSetupMock from './setup-mock';
import createSetupVisualizer from './setup-visualizer';
import Icons from 'unplugin-icons/vite';
import IconsResolver from 'unplugin-icons/resolver';
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers';
import Components from 'unplugin-vue-components/vite';
import vueJsx from '@vitejs/plugin-vue-jsx'; // 添加这一句

export default function createVitePlugins(viteEnv, isBuild = false) {
  const vitePlugins = [vue()];
  vitePlugins.push(vueJsx());
  vitePlugins.push(createAutoImport());
  vitePlugins.push(createSetupExtend());
  vitePlugins.push(createSetupMock());
  vitePlugins.push(createSetupVisualizer());
  vitePlugins.push(Components({
    resolvers: [IconsResolver(), ElementPlusResolver()],
    directoryAsNamespace: true,
  }));

  vitePlugins.push(Icons({
    autoInstall: true,
  }));
  if (isBuild) {
    vitePlugins.push(...createCompression(viteEnv));
  }
  return vitePlugins;
}
